package io.adrainty.bolee.framework.commons.user;

/**
 * 用户主体对象
 * @author AdRainty
 * @version V1.0.0
 * @since 2025/8/3 下午10:53
 */
public class SubjectContentUtil {

    private SubjectContentUtil() {}

    /**
     * 创建线程局部userVO变量
     */
    public static ThreadLocal<UserEntity> userVOThreadLocal = ThreadLocal.withInitial(() -> null);

    /**
     * 创建线程局部dataSecurityVO变量
     */
    public static ThreadLocal<DataSecurityEntity> dataSecurityVOThreadLocal = ThreadLocal.withInitial(() -> null);

    /**
     * 创建线程局部companyNo变量
     */
    public static ThreadLocal<String> companyNoThreadLocal = ThreadLocal.withInitial(() -> null);

    /**
     * 创建线程局部userToken变量
     */
    public static ThreadLocal<String> userTokenThreadLocal = ThreadLocal.withInitial(() -> null);

    /**
     * 设置公司编号
     * @param companyNo 公司编号
     */
    public static void setCompanyNo(String companyNo) {
        companyNoThreadLocal.set(companyNo);
    }

    /**
     * 设置用户数据权限
     * @param dataSecurityVO 用户权限
     */
    public static void setDataSecurityVO(DataSecurityEntity dataSecurityVO) {
        dataSecurityVOThreadLocal.set(dataSecurityVO);
    }

    /**
     * 设置用户主体对象
     * @param userVO 用户主体对象
     */
    public static void setUserVO(UserEntity userVO) {
        userVOThreadLocal.set(userVO);
    }

    /**
     * 设置用户令牌
     * @param userToken 用户令牌
     */
    public static void setUserToken(String userToken) {
        userTokenThreadLocal.set(userToken);
    }

    /**
     * 获取公司编号
     * @return 公司编号
     */
    public static String getCompanyNo() {
        return companyNoThreadLocal.get();
    }

    /**
     * 获取用户数据权限
     * @return 用户数据权限
     */
    public static DataSecurityEntity getDataSecurityVO() {
        return dataSecurityVOThreadLocal.get();
    }

    /**
     * 获取用户主体对象
     * @return 用户主体对象
     */
    public static UserEntity getUserVO() {
        return userVOThreadLocal.get();
    }

    /**
     * 获取用户令牌
     * @return 用户令牌
     */
    public static String getUserToken() {
        return userTokenThreadLocal.get();
    }

    /**
     * 清空当前线程companyNo
     */
    public static void removeCompanyNo() {
        companyNoThreadLocal.remove();
    }

    /**
     * 清空当前线程dataSecurityVO
     */
    public static void removeDataSecurityVO() {
        dataSecurityVOThreadLocal.remove();
    }

    /**
     * 清空当前线程userVO
     */
    public static void removeUserVO() {
        userVOThreadLocal.remove();
    }

    /**
     * 清空当前线程userToken
     */
    public static void removeUserToken() {
        userTokenThreadLocal.remove();
    }

}
